package com.ossean;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.annotation.Resource;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;

import com.ossean.databaseSource.GatherDao;
import com.ossean.model.EddRelations;
import com.ossean.model.GatherProjectsModel;
import com.ossean.util.MergeProjectsUtil;
import com.ossean.util.StringHandler_ProjectName;
import com.ossean.util.TransferProjectsUtil;


@Component
public class Test {

	@Resource
	private TransferProjectsUtil util;
	@Resource
	private MergeProjectsUtil mergeUtil;
	@Resource
	private GatherDao gatherDao;
	
	private MergeProjectsByHomepageOnly mergeHomepage;
	

	
	String synonyms = "<maven>,<maven>,<hello>,<shit>,<finally>,<shit>,";
	String synonyms2 = "";
	
	String name = "   mozillasolr   ";
	String description = " shit is very good";
	String homepage = "http://www.7-zip.org/";
	
	String tag1 = "<1>,<2>,<3>,<4>,<5>";
	String tag2 = "<3>,<4>";
	
	String source1 = "sourceforge";
	String source2 = "sourceforge";
	
	
	public void start(){
		//测试combineNewEddRelations函数
		EddRelations relation1 = new EddRelations();
		EddRelations relation2 = new EddRelations();
		EddRelations relation3 = new EddRelations();
		String gather_projects_ids1 = ",1,2,3,4,";
		String gather_projects_ids2 = ",1,";
		String gather_projects_ids3 = ",3,4,5,6,";
		
		String[] array1 = gather_projects_ids1.split(",");
		String[] array2 = gather_projects_ids2.split(",");
		
//		boolean result = containArray(array1, array2);
		
		relation1.setGather_projects_ids(gather_projects_ids1);
		relation2.setGather_projects_ids(gather_projects_ids2);
		relation3.setGather_projects_ids(gather_projects_ids3);
		
		List<EddRelations> relationList = new ArrayList<EddRelations>();
		relationList.add(relation2);
		relationList.add(relation3);
		relationList.add(relation1);
		
		EddRelations result = findLongestGatherProjectsIds(relationList);
		
//		EddRelations result = combineNewEddRelation(relationList);
//		System.out.println(result.getGather_projects_ids());
	}
	
	
	private EddRelations findLongestGatherProjectsIds(List<EddRelations> eddRelationList){
		EddRelations result = new EddRelations();
		int maxLength = 0;
		for(EddRelations relation:eddRelationList){
			String gather_projects_ids = relation.getGather_projects_ids();
			int length = gather_projects_ids.split(",").length-1;
			if(length > maxLength){
				maxLength = length;
				result = relation;
			}
		}
		return result;
	}
	
	public static void main(String[] args){
		ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:/applicationContext*.xml");
		Test Main = applicationContext.getBean(Test.class);
		Main.start();
	}
	
}
